-----------------------------------
-- Area: Port Bastok
-- NPC: Alib-Mufalib
-- Type: Warp NPC
-- Quests: Lure of the Wildcat
-- (Bastok)
-- @zone 236
-- @pos 116.080 8.372 -31.820
-- Note: After this quest and Aht
-- Urghan mission 2, he will
-- teleport you to Aht Urghan for
-- 300g.
-----------------------------------
package.loaded["scripts/zones/Port_Bastok/TextIDs"] = nil;
-----------------------------------

require("scripts/globals/settings");
require("scripts/globals/quests");
require("scripts/globals/missions");
require("scripts/globals/teleports");
require("scripts/globals/keyitems");
require("scripts/zones/Port_Bastok/TextIDs");

--[[
Bitmask Designations:
Port Bastok (East to West)
00001   (J-5) Kaede (northernmost house) 
00002   (F-5) Patient Wheel (north of Warehouse 2) 
00004   (F-6) Paujean (bottom floor of Warehouse 2) 
00008   (E-6) Hilda (Steaming Sheep Restaurant, walks on the top floor and occasionally down. However, she can still be talked to when on second floor. Unable to get if you have Cid's Secret flagged.) 
00010   (F-8) Tilian (end of a pier west of Air Travel Agency) 

Metalworks (all found on top floor)
00020    (G-8) Raibaht (Cid's lab) 
00040    (G-8) Invincible Shield (outside Cid's Lab) 
00080    (G-7) Manilam (on top of Cermet Refinery) 
00100    (I-8) Kaela (between Consulate of Windurst & Consulate of Bastok) 
00200    (K-7) Ayame (Inside north Cannonry) 

Bastok Markets (East to West)
00400    (K-10) Harmodios (Harmodios's Music Shop) 
00800    (J-10) Arawn (west of music store) 
01000    (I-9) Horatius (Inside Trader's Home) 
02000    (E-10) Ken (outside Mjoll's General Goods) 
04000    (E-11) Pavel (West Gate to South Gustaberg) 

Bastok Mines (Clockwise, starting at Ore Street, upper floor to lower floor)
08000    (H-5) Griselda (upper floor, Bat's Lair Inn) 
10000    (I-6) Goraow (upper floor, in stairwell of Ore Street) 
20000    (I-7) Echo Hawk (lower floor, Ore Street) 
40000    (H-6) Deidogg (lower floor, Ore Street) 
80000    (H-9) Vaghron (southwest of South Auction House) 
]]--

-----------------------------------
-- onTrade Action
-----------------------------------

function onTrade(player,npc,trade)
	if ((WILDCAT_WARP_ENABLE  == true) and trade:getGil() == 300 and trade:getItemCount() == 1) then
		player:startEvent(0x017B);
	elseif (trade:getGil() == 300 and trade:getItemCount() == 1 and player:getQuestStatus(BASTOK,LURE_OF_THE_WILDCAT_BASTOK) == QUEST_COMPLETED and player:getCurrentMission(TOAU) > IMMORTAL_SENTRIES) then 
		-- Needs a check for at least traded an invitation card to Naja Salaheem
		player:startEvent(0x017B);
	end

end;

-----------------------------------
-- onTrigger Action
-----------------------------------

function onTrigger(player,npc)
	local LureBastok = player:getQuestStatus(BASTOK,LURE_OF_THE_WILDCAT_BASTOK);
	local WildcatBastok = player:getVar("WildcatBastok");
	if (LureBastok ~= 2 and ENABLE_TOAU == 1) then
		if (LureBastok == 0) then
			player:startEvent(0x0165);
		else
			if (WildcatBastok == 0) then
				player:startEvent(0x0166);
			elseif (player:isMaskFull(WildcatBastok,20) == true) then
				player:startEvent(0x0168);
			else
				player:startEvent(0x0167);
			end
		end
	elseif(player:getCurrentMission(TOAU) >= 2) then
		player:startEvent(0x017A);
	else
		player:startEvent(0x0169);
	end
end;

-----------------------------------
-- onEventFinish Action
-----------------------------------

function onEventFinish(player,csid,option)
	-- printf("CSID: %u",csid);
	-- printf("RESULT: %u",option);
	if (csid == 0x0165) then
		player:addQuest(BASTOK,LURE_OF_THE_WILDCAT_BASTOK);
		player:setVar("WildcatBastok",0);
		player:addKeyItem(BLUE_SENTINEL_BADGE);
		player:messageSpecial(KEYITEM_OBTAINED,BLUE_SENTINEL_BADGE);
	elseif(csid == 0x0168) then
		player:completeQuest(BASTOK,LURE_OF_THE_WILDCAT_BASTOK);
		player:addFame(BASTOK,150);
		player:setVar("WildcatBastok",0);
		player:delKeyItem(BLUE_SENTINEL_BADGE);
		player:addKeyItem(BLUE_INVITATION_CARD);
		player:messageSpecial(KEYITEM_LOST,BLUE_SENTINEL_BADGE);
		player:messageSpecial(KEYITEM_OBTAINED,BLUE_INVITATION_CARD);
	elseif(csid == 0x017B) then
		player:tradeComplete();
		toAhtUrhganWhitegate(player);
	end
end;
